﻿@{
    ViewBag.Title = "体检套餐管理";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<style type="text/css">
    .layout-split-west {
        border-right-color: Window;
    }
</style>

<div class="easyui-layout" data-options="fit:true" scroll="no">
    <div data-options="region:'center',noheader:true,border:false">
        <table id="dgMedicalPackage"></table>
    </div>
</div>
<div id="tbar">
    <div class="tbar">
        <div class="z-toolbar">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-arrow_refresh',plain:true" onclick="ToolbarRefresh();">刷新</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="ToolbarAdd();">增加</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="ToolbarEdit();">编辑</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cross',plain:true" onclick="ToolbarRemove();">删除</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="ToolbarUnselect();">取消选中</a>
        </div>
        <form id="searchForm">
            <table>
                <tr>
                    <td>套餐名称:</td>
                    <td class="td-left"><input type="text" name="MPName" class="easyui-textbox" /></td>
                    <td class="td-right"><a id="btnSearch" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="btnSearch_OnClick()">查询</a></td>
                    <td class="td-right"><a id="btnSearch" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-undo'" onclick="cancelSearch()">取消</a></td>
                </tr>
            </table>
        </form>
    </div>
</div>
@section PageSpecificScript{
    <script type="text/javascript">
        var dgMedicalPackage;/*显示套餐*/
        var sexData;
        var marryData;
        var searchForm;
        $(document).ready(function () {
            sexData = [
             {
                 value: 0,
                 text: '女'
             },
             {
                 value: 1,
                 text: '男'
             },
             {
                 value: 2,
                 text: '不限'
             }];
            marryData = [
             {
                 value: 0,
                 text: '未婚'
             },
             {
                 value: 1,
                 text: '已婚'
             },
             {
                 value: -1,
                 text: '不限'
             }];
            searchForm = $("#searchForm");
            $.validateUrl("/Admin/BS_MedicalPackage/GetMedicalPackageByCondition", function () {
                dgMedicalPackage = $("#dgMedicalPackage").datagrid({
                    url: '/Admin/BS_MedicalPackage/GetMedicalPackageByCondition',
                    method: 'Get',
                    idField: 'MPId',
                    fit: true,
                    fitColumns: true,
                    rownumbers: true,
                    striped: true,
                    pagination: true,
                    singleSelect: true,
                    toolbar: '#tbar',
                    pageSize: 20,
                    pageList: [20, 30, 40, 50],
                    frozenColumns: [[
                        { field: 'MPId', title: 'MPId', hidden: true }
                    ]],
                    columns: [[
                        { field: 'MPName', title: '套餐名称', width: 90, halign: 'center' },
                        { field: 'MPCode', title: '套餐编码', width: 80, halign: 'center', align: 'center' },
                        { field: 'MPEcomCode', title: '电商编码', width: 80, halign: 'center', align: 'center' },
                        {
                            field: 'MPSex', title: '适用性别', width: 60, halign: 'center', align: 'center', formatter: function (value, row, index) {
                                if (value == 0) {
                                    return "女";
                                } else if(value==1){
                                    return "男";
                                } else if (value == 2) {
                                    return "不限";
                                }
                            }
                        },
                        {
                            field: 'MPMarried', title: '婚姻状况', width: 60, halign: 'center', align: 'center', formatter: function (value, row, index) {
                                if (value == 0) {
                                    return "未婚";
                                } else if (value == 1) {
                                    return "已婚";
                                } else if (value == -1) {
                                    return "不限";
                                }
                            }
                        },
                        { field: 'MPDescription', title: '备注', width: 120, halign: 'center' },
                        {
                            field: 'MPCreateTime', title: '创建日期', width: 80, halign: 'center', align: 'center', formatter: function (value, row, index) {
                                if (value) {
                                    return eval("new " + value.substr(1, value.length - 2)).toLocaleDateString();
                                }
                            }
                        }
                    ]],
                    onDblClickRow: function (rowIndex, rowData) {
                        if (editRow != undefined) {
                            dgMedicalPackage.datagrid('endEdit', editRow);
                        } else {
                            dgMedicalPackage.datagrid('beginEdit', rowIndex);
                            editUser = rowIndex;
                            dgMedicalPackage.datagrid('selectRow', editUser);
                        }
                    },
                    onRowContextMenu: function (e, rowIndex, rowData) {
                        e.preventDefault();
                        $(this).datagrid("unselectAll");
                        $(this).datagrid("selectRow", rowIndex);
                        $("#menu").menu('show', {
                            left: e.pageX,
                            top: e.pageY
                        });
                    }
                });
            });
        }, xz.dealWith, 'GET');
        /*过滤用户信息*/
        function btnSearch_OnClick() {
            dgMedicalPackage.datagrid('load', xz.serializeObject(searchForm));
        }
        /*取消过滤用户信息*/
        function cancelSearch() {
            searchForm.form('clear');
            dgMedicalPackage.datagrid('load', {});
        }
        /**刷新菜单**/
        function ToolbarRefresh() {
            dgMedicalPackage.datagrid("load");
        }
        /**增加菜单**/
        function ToolbarAdd() {
            showAppendView();
        }
        /**编辑菜单**/
        function ToolbarEdit() {
            showEditView();
        }
        /**删除菜单**/
        function ToolbarRemove() {
            removeUser();
        }
        /**取消选中菜单**/
        function ToolbarUnselect() {
            dgMedicalPackage.datagrid("unselectAll");
        }
        /*打开添加的页面*/
        function showAppendView() {
            $.validateUrl('/Admin/BS_MedicalPackage/EditView', append, xz.dealWith, 'GET');
        }
        /*新增体检套餐*/
        function append() {
            var pAdd = xz.dialog({
                title: '新增体检套餐',
                width: 680,
                height: 350,
                iconCls: 'icon-add',
                href: '/Admin/BS_MedicalPackage/EditView',
                buttons: [{
                    text: '新增',
                    iconCls: 'icon-add',
                    handler: function () {
                        var f = pAdd.find('form');
                        f.form('submit', {
                            url: '/Admin/BS_MedicalPackage/AddMedicalPackage',
                            onSubmit: function () {
                                return true;
                            },
                            success: function (jsonData) {
                                jsonData = $.parseJSON(jsonData);
                                $.procAjaxMsg(jsonData, function () {
                                    pAdd.dialog('close');
                                    dgMedicalPackage.datagrid("reload");
                                    $.alertMsg(jsonData.Msg, "操作提示", null);
                                }, function () {
                                    $.alertMsg(jsonData.Msg, "操作提示", null);
                                });
                            }
                        });
                    }
                }, {
                    text: '关闭',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        pAdd.dialog('close');
                    }
                }],
                onLoad: function () {
                    var f = pAdd.find('form');
                    var mpName = f.find('input[name=MPName]');
                    var mpSex = f.find('input[name=MPSex]');
                    var mpMarried = f.find('input[name=MPMarried]');
                    var mpItems = f.find('input[name=MPItems]');

                    window.setTimeout(function () {
                        mpName.focus();
                    }, 100);

                    mpSex.combobox({
                        data: sexData
                    });

                    mpMarried.combobox({
                        data: marryData
                    });

                    mpItems.combogrid({
                        url: '/Admin/BS_MedicalItem/GetMedicalItemGrid',
                        required: true,
                        loadMsg: '数据加载中......',
                        panelWidth: 510,
                        panelHeight: 180,
                        fitColumns: true,
                        multiple: true,
                        singleSelect: false,
                        idField: 'MIId',
                        textField: 'MICheckItemName',
                        method: 'Get',
                        mode: 'remote',
                        pagination: true,
                        pageSize: 5,
                        pageList: [5, 10],
                        columns: [[
                            { field: 'MIId', title: 'MIId', checkbox: true },
                            { field: 'MICheckItemName', title: '项目名称', width: 100 },
                            { field: 'MIClinicMeaning', title: '项目说明', width: 400 }
                        ]]
                    });
                }
            })
        }

        /*编辑套餐信息*/
        function showEditView() {
            $.validateUrl('/Admin/BS_MedicalPackage/EditView', edit, xz.dealWith, 'Get');
        }
        /*编辑套餐信息*/
        function edit() {
            var node = dgMedicalPackage.datagrid("getSelected");
            var dgDepartment;
            if (node) {
                var pAdd = xz.dialog({
                    title: '修改体检套餐',
                    width: 680,
                    height: 350,
                    iconCls: 'icon-edit',
                    href: '/Admin/BS_MedicalPackage/EditView',
                    buttons: [{
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function () {
                            var f = pAdd.find('form');
                            f.form('submit',{
                                url: '/Admin/BS_MedicalPackage/EditMedicalPackage',
                                success: function (jsonData) {
                                    jsonData = $.parseJSON(jsonData);
                                    $.procAjaxMsg(jsonData, function () {
                                        pAdd.dialog('close');
                                        dgMedicalPackage.datagrid("reload");
                                        $.alertMsg(jsonData.Msg, "操作提示", null);
                                    }, function () {
                                        $.alertMsg(jsonData.Msg, "操作提示", null);
                                    });
                                }
                            });
                        }
                    }, {
                        text: '关闭',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            pAdd.dialog('close');
                        }
                    }],
                    onLoad: function () {
                        var f = pAdd.find('form');
                        var mpName = f.find('input[name=MPName]');
                        var mpSex = f.find('input[name=MPSex]');
                        var mpMarried = f.find('input[name=MPMarried]');
                        var mpItems = f.find('input[name=MPItems]');

                        window.setTimeout(function () {
                            mpName.focus();
                        }, 100);

                        mpSex.combobox({
                            data: sexData
                        });

                        mpMarried.combobox({
                            data: marryData
                        });

                        mpItems.combogrid({
                            url: '/Admin/BS_MedicalItem/GetMedicalItemGrid',
                            required: true,
                            loadMsg: '数据加载中......',
                            panelWidth: 510,
                            panelHeight: 180,
                            fitColumns: true,
                            multiple:true,
                            singleSelect:false,
                            idField: 'MIId',
                            textField: 'MICheckItemName',
                            method: 'Get',
                            mode: 'remote',
                            pagination: true,
                            pageSize: 5,
                            pageList: [5, 10],
                            columns: [[
                                { field: 'MIId', title: 'MIId', checkbox: true },
                                { field: 'MICheckItemName', title: '项目名称', width: 100 },
                                { field: 'MIClinicMeaning', title: '项目说明', width: 400 }
                            ]]
                        });

                        /*把选中的信息绑定到对应的表单上*/
                        f.form('load', node);
                    }
                })
            } else {
                xz.messageAlert("提示", "请选择要修改的体检套餐", "error");
            }
        }

        /*删除体检套餐*/
        function removeUser() {
            var rows = dgMedicalPackage.datagrid("getSelected");
            if (rows) {
                xz.messageConfirm('询问', '你确定要删除【' + rows.MPName + '】吗?', function (b) {
                    if (b) {
                        $.ajax({
                            type: 'POST',
                            url: '/Admin/BS_MedicalPackage/DelMedicalPackage',
                            data: {
                                MPId: rows.MPId
                            },
                            cache: false,
                            dataType: 'JSON',
                            success: function (jsonData) {
                                $.procAjaxMsg(jsonData, function () {
                                    dgMedicalPackage.datagrid("reload");
                                    $.alertMsg(jsonData.Msg, "操作提示", null);
                                }, function () {
                                    $.alertMsg(jsonData.Msg, "操作提示", null);
                                });
                            }
                        });
                    }
                });
            } else {
                xz.messageAlert("提示", "请选择要删除的体检套餐", "error");
            }
        }
    </script>
}
